//
//  ScanViewController.m
//  嘀嘀拍
//
//  Created by 陈一航 on 16/3/3.
//  Copyright (c) 2016年 wangjia_01. All rights reserved.
//

#import "ScanViewController.h"
//#import "ZBarSDK.h"

@interface ScanViewController ()
//<ZBarReaderViewDelegate>

//{
//    ZBarReaderView *_readerView;
//}

@property (weak, nonatomic) IBOutlet UIView *scanView;



@end

@implementation ScanViewController

/*
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //初始化照相机窗口
    _readerView= [ZBarReaderView new];
    //自定义大小
    _readerView.frame = self.scanView.frame;
    //自定义添加相关指示.........发挥各自的APP的想象力
    //此处省略美化10000行代码...................
    //………………………..
    // 好进入正题—— 接着设置好代理
    _readerView.readerDelegate = self;
    _readerView.enableCache=YES;
    
    //将其照相机拍摄视图添加到要显示的视图上
    [self.scanView addSubview:_readerView];
    //二维码/条形码识别设置
    ZBarImageScanner *scanner = _readerView.scanner;
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    //启动，必须启动后，手机摄影头拍摄的即时图像菜可以显示在readview上
    [_readerView start];
    
    //    ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
    //    reader.readerDelegate=self;
    //    reader.sourceType = UIImagePickerControllerSourceTypeCamera;
    //    ZBarImageScanner * scanner = reader.scanner;
    //    [scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
    //    reader.showsZBarControls = YES;
    
    // [self presentViewController:reader animated:YES completion:nil];
    
       
}

- (void) readerView: (ZBarReaderView*) readerView
     didReadSymbols: (ZBarSymbolSet*) symbols
          fromImage: (UIImage*) image
{
    
    
    ZBarSymbol * symbol=nil;
    for(symbol in symbols)
        break;

    if (symbol.data) {
        DLog(@"SYMBOL:%@",symbol.data);
        _readerView=readerView;
        [_readerView stop];
        [_readerView flushCache];
        if (self.delegate && [self respondsToSelector:@selector(getTwoDCode:)]) {
            
            [self.delegate getTwoDCode:symbol.data];
            [self .navigationController popViewControllerAnimated:YES];
        }
        
    }
    
    
}

- (NSString *)getTwoDCode:(NSString *)code
{
    return @"";
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
